﻿using Basmus.ReadWrite;

namespace Basmus.Values.Attributive.ReadWrite
{
    public class NullableReaderWriterBuilder<TValue> : IReaderWriterBuilder<TValue?>
        where TValue : struct
    {
        private readonly IReaderWriterBuilder<TValue> _readerWriterBuilder;

        public NullableReaderWriterBuilder(IReaderWriterBuilder<TValue> readerWriterBuilder)
        {
            _readerWriterBuilder = readerWriterBuilder;
        }

        public IReaderWriter<TValue?> Build(ValuesContext valuesContext)
        {
            var valueReaderWriter = _readerWriterBuilder.Build(valuesContext);
            return new NullableReaderWriter<TValue>(valueReaderWriter);
        }
    }
}